MODE_IN: int = 1
MODE_OUT: int = 2
MODE_OD:int = 3
MODE_IRQ: int = 4

PULL_NONE: int = 1
PULL_UP: int = 2
PULL_DOWN: int = 3

IRQ_RISING: int = 1
IRQ_FALLING: int = 2
IRQ_BOTH: int = 3

HIGH: int = 1
LOW: int = 0


def __init__(self): ...


class GPIO(BaseDev):

    # TODO: 增加上下拉、引脚模式常量  -- 2024-11-13

    def __init__(self, name: str): ...


    def get_name(self) -> str:
        """
        Get the name of the pin.
        """
    
    def open(self, mode: int, pull: int, speed: int):
        """
        Set the mode of the pin.
        example: "in", "out" ...
        """

    def iomux(self, altfunc:int):
        """
        Set the alt function of the pin.
        """
    
    def enable_IT(self, irq: int, evt_cbk: any):
        """
        Set the interrupt of the pin.
        """
    def disable_IT(self, irq: int): 
        """
        Disable the interrupt of the pin.
        """
        
    def set_mode(self, mode: int):
        """
        Set the mode of the pin.
        example: "in", "out" ...
        """

    def set_pull(self, pull: int):
        """
        Set the pull of the pin.
        example: `"up"`, `"down"`, `"none"` ...
        """
        
    def set_speed(self, speed: int):
        """
        Set the pull of the pin.
        example: `"up"`, `"down"`, `"none"` ...
        """
    
        
    def write(self, lv: int):
        """Write the pin value."""

    def read(self) -> int:
        """Read the pin value."""
        
        
    def get_mode(self) -> int:
        """
        Get the mode of the pin.
        """

    def get_pull(self) -> int:
        """
        Get the pull of the pin.
        """
        
    def get_speed(self) -> int:
        """
        Get the pull of the pin.
        """

    def close(self): 
        """
        Close the pin.
        """
    def __del__(self): ...


STOP_BITS_1: int = 1
STOP_BITS_2: int = 2
STOP_BITS_1_5: int = 3 

PARITY_NONE: int = 1
PARITY_EVEN: int = 2
PARITY_ODD: int = 3

FLOW_CONTROL_NONE: int = 1
FLOW_CONTROL_RTS: int = 2
FLOW_CONTROL_CTS: int = 3
FLOW_CONTROL_RTS_CTS: int = 4

SIGNAL_RX: int = 1
SIGNAL_TX: int = 2

class UART(BaseDev):
    
    def __init__(self, name: str): ...
    
    def get_name(self) -> str: ...
    
    def open(self, baudrate: int, databits: int, stopbits: int, parity: int): ...

    def remap(self, tx_name: str, rx_name: str): 
        """映射引脚"""

    def write(self, data: bytes, length: int):
        """Write string to the UART."""

    def read(self, length: int) -> bytes:
        """Read string from the UART."""

    def enable_IT(self, irq: int, evt_cbk: any):
        """
        Set the  interrupt of the uart.
        """
    def disable_IT(self, irq: int): 
        """
        Disable the  interrupt of the uart.
        """
    
    def close(self): ...
    
    def __del__(self): ...


MASTER: int = 1
SLAVE: int = 2
MODE_0: int = 1
MODE_1: int = 2
MODE_2: int = 3
MODE_3: int = 4
LSB: int = 1
MSB: int = 2
DATA_WIDTH_8 :int = 8
DATA_WIDTH_16 :int = 16
HALF_DUPLEX: int = 1
FULL_DUPLEX: int = 2

class SPI(BaseDev):
    def __init__(self, name: str): ...

    def get_name(self) -> str: ...
    
    def open(self, cs_name: any, mode: int, data_width: int, bit_dict: int, is_master: int, speed: int, duplex: int): ...
    
    def remap(self, mosi_name: str, miso_name: str, sclk_name: str): 
        """映射引脚"""
        
    def write(self, data: bytes, length: int):
        """Write bytes to the SPI."""

    def read(self, length: int) -> bytes:
        """Read bytes from the SPI."""
        
    # def write_read(self, data: bytes, length: int) -> bytes:
    #     """Read bytes from the SPI."""
    #
    # def enable_IT(self, irq: int, evt_cbk: any):
    #     """
    #     Set the  interrupt of the spi.
    #     """
    # def disable_IT(self, irq: int): 
    #     """
    #     Disable the  interrupt of the spi.
    #     """
        
    def close(self): ...
    
    def __del__(self): ...


class I2C(BaseDev):
    def __init__(self, name: str): ...

    def get_name(self) -> str: ...
    
    def open(self, speed:int): ...
    
    def remap(self, sda_name: str, scl_name: str): 
        """映射引脚"""
        
    def write(self, data: bytes, length: int):
        """Write bytes to the I2C."""

    def read(self, length: int) -> bytes:
        """Read bytes from the I2C."""
    
    def close(self): ...
    
    def __del__(self): ...

class BaseDev:
    @PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
    def addEventCallback(self, eventCallback: any):
        """ Add an event callback. """

    def addEventCallBack(self, eventCallback: any):
        """ deprecated, use addEventCallback instead. """

    @abstractmethod
    @PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
    def platformGetEventId(self): ...
    
    
